package com.iqiyi.qigsaw.sample.java;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.dhy.annotations.Component;
import com.dhy.qigsaw.splash.data.TestCase;

import acom.dhy.qigsaw2test.App;
import acom.dhy.qigsaw2test.qigsaw.CrossServiceKt;
import acom.dhy.qigsaw2test.qigsaw.DynamicFeatureKt;

@Component
public class JavaSampleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_java_sample);
        App.getTestCases().put(TestCase.JAVA, true);

        View btService = findViewById(R.id.btService);
        btService.setOnClickListener(v -> {
            Intent intent = new Intent(this, MyService.class);
            startService(intent);
        });
        View btBroadcast = findViewById(R.id.btBroadcast);
        btBroadcast.setOnClickListener(v -> {
            Intent msg = new Intent(MyReceiver.class.getName());
            msg.setPackage(getPackageName());
            sendBroadcast(msg);
        });
        View btDisplayAssets = findViewById(R.id.btDisplayAssets);
        btDisplayAssets.setOnClickListener(v -> {
            DynamicFeatureKt.displayAssets(this);
        });
        View btCrossService = findViewById(R.id.btCrossService);
        btCrossService.setOnClickListener(v -> {
            CrossServiceKt.crossServiceShowTip(this);
        });

        if (App.AUTO_TEST_MODE) {
            btService.performClick();
            btBroadcast.performClick();
            btDisplayAssets.performClick();
            btCrossService.performClick();

            btCrossService.postDelayed(this::finish, 1500);
        }
    }
}
